//
//  UIButton+Extension.swift
//  Sina
//
//  Created by  duan on 16/4/6.
//  Copyright © 2016年 duan. All rights reserved.
//  按钮的类延展, 用于快速创建按钮
//
import UIKit

//定义一个button 的延展:
extension UIButton{

    //便利构造函数:
    convenience init(imageName: String, BackImageName: String) {
        //调用系统的构造函数:
        self.init()
        
        //设置图片:
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        setBackgroundImage(UIImage(named: BackImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: BackImageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        
        //根据背景的大小自动调整尺寸
        sizeToFit()
        
        
        
    }

    ///便利构造函数:
    convenience init(text: String, textSize:CGFloat, color: UIColor,  backGroundImage: String?){
    self.init()
       setTitle(text, forState: .Normal)
        
//        titleLabel?.text = text
       setTitleColor(color, forState: .Normal)
        
//        titleLabel?.textColor = color
        titleLabel?.font = UIFont.systemFontOfSize(textSize)
       
        if let backImage = backGroundImage{
        
        setBackgroundImage(UIImage(named: backImage), forState: UIControlState.Normal)
        
        }
        
        
        sizeToFit()
        
    }





}

